package com.sphd.restaurantsystem.adapters;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sphd.restaurantsystem.R;
import com.sphd.restaurantsystem.info.SalesInfo;

import java.util.List;

/**
 * Created by Hu on 2016/11/4.
 */

public class SalesAdapter extends BaseQuickAdapter<SalesInfo> {
    private static final String TAG = "SalesAdapter";
    int DATETYPE;
    int FLAG;
    Context context;

    public SalesAdapter(int layoutResId, List<SalesInfo> data, Context context) {
        super(layoutResId, data);
        this.context=context;
    }


    @Override
    protected void convert(BaseViewHolder baseViewHolder, SalesInfo salesInfo) {
        TextView payTv = baseViewHolder.getView(R.id.type_pay_textview);
        if (DATETYPE == 3) {
            payTv.setVisibility(View.VISIBLE);
            if (salesInfo.getOrder_pay() == 0) {
                if (TextUtils.isEmpty(salesInfo.getOrder_memcard())) {
                    payTv.setText("现");
                    payTv.setBackgroundColor(context.getResources().
                            getColor(R.color.red));
                } else {
                    payTv.setText("折");
                    payTv.setBackgroundColor(context.getResources().
                            getColor(R.color.orange));
                }

            } else {
                payTv.setText("充");
                payTv.setBackgroundColor(context.getResources().
                        getColor(R.color.indigo_500));
            }

        } else {
            payTv.setVisibility(View.GONE);
        }

        baseViewHolder.setText(R.id.date, DATETYPE != 3 ? salesInfo.getTime() : FLAG == 2 ?
                "桌号" + salesInfo.getTableno() : "订单编号" + salesInfo.getOrder_no())
                .setText(R.id.all_money, DATETYPE != 3 ? "￥" + salesInfo.getSum() : "￥" + salesInfo.getOrder_lastprice())
                .setText(R.id.count, DATETYPE != 3 ? "共有" + salesInfo.getCount() + "笔订单" : salesInfo.getOrder_fintime());

    }

    public void setType(int datetype, int flag) {
        this.DATETYPE = datetype;
        this.FLAG = flag;
    }
}
